//
//  DYHomeView.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/11.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYHomeView.h"

@implementation DYHomeView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end


@interface DYHomeNoEnterView ()

@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UIButton *enterButton;

@end

@implementation DYHomeNoEnterView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}

-(void)initUI
{
    self.backgroundColor=WhiteColor;
    
    self.titleLabel = ({
        UILabel *label=[Utils labelWithTitle:@"登录成功，卡福欢迎您！" titleFontSize:24 textColor:[UIColor xhq_aTitle] backgroundColor:WhiteColor alignment:0];
        label;
    });
    
    self.enterButton = ({
        UIButton *button = [Utils createBtnWithType:UIButtonTypeCustom backgroundColor:[UIColor xhq_base] action:@selector(enterButtonClick) target:self title:@"入驻开店" image:nil font:18 textColor:WhiteColor];
        [button xhq_cornerRadius:BILIHEIGHT(18)];
        button;
    });
    
    [self addSubview:self.titleLabel];
    [self addSubview:self.enterButton];
    
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(10));
        make.top.equalTo(BILIHEIGHT(20));
    }];
    
    [self.enterButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.bottom).offset(BILIHEIGHT(20));
        make.centerX.equalTo(self);
        make.size.equalTo(CGSizeMake(BILIWIDTH(136), BILIHEIGHT(36)));
    }];
    
}

-(void)enterButtonClick
{
    if (self.enterBlock) {
        self.enterBlock();
    }
}

@end



@interface DYHomeEnterView ()

@property (nonatomic,strong)UIImageView *bgView;
@property (nonatomic,strong)UIButton *scanButton;
@property (nonatomic,strong)UIButton *barcodeButton;

@end

@implementation DYHomeEnterView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
-(void)initUI
{
    self.backgroundColor=WhiteColor;
    
    self.bgView = ({
        UIImageView *view=[Utils imageViewWithImage:IMG(@"bg_firstpage")];
        view.contentMode=UIViewContentModeScaleToFill;
        view;
    });
    
    self.scanButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(buttonClick:) target:self title:@"扫码收款" image:@"icon_scan_first" font:14 textColor:WhiteColor];
        button;
    });
    
    self.barcodeButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(buttonClick:) target:self title:@"收款条码" image:@"icon_ma_first" font:14 textColor:WhiteColor];
        button;
    });
    
    [self addSubview:self.bgView];
    [self addSubview:self.scanButton];
    [self addSubview:self.barcodeButton];
    
    
    [self.bgView makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.equalTo(CGSizeMake(BILIWIDTH(355), BILIHEIGHT(108)));
    }];
    
    [self.scanButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bgView);
        make.right.equalTo(self).offset(-kScreenWidth/2-BILIWIDTH(20));
        make.width.equalTo(BILIWIDTH(108));
        make.height.equalTo(BILIHEIGHT(100));
    }];
    
    [self.barcodeButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bgView);
        make.left.equalTo(self).offset(kScreenWidth/2+BILIWIDTH(20));
        make.width.equalTo(BILIWIDTH(108));
        make.height.equalTo(BILIHEIGHT(100));
    }];
    
    [self.scanButton placeImageTitlePosition:ZYButtonImagePositionTop space:BILIHEIGHT(7)];
    [self.barcodeButton placeImageTitlePosition:ZYButtonImagePositionTop space:BILIHEIGHT(7)];
}
-(void)buttonClick:(UIButton *)button
{
    if (button==self.barcodeButton) {
        !self.paymentCodeBlock?:self.paymentCodeBlock();
    }
}
@end



@interface DYHomeActivityView ()

@property (nonatomic,strong) DYHomeActivityChildView *saleView;
@property (nonatomic,strong) DYHomeActivityChildView  *newsView;
@property (nonatomic,strong) UILabel *line;



@end


@implementation DYHomeActivityView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
-(void)initUI
{
    self.backgroundColor=WhiteColor;
    
    self.saleView = ({
        DYHomeActivityChildView *view=[[DYHomeActivityChildView alloc]init];
        view.imageNameStr=@"icon_markmanage";
        view.titleStr=@"营销管理";
        view.contentStr=@"会员卡充值活动";
        view;
    });
    
    self.newsView = ({
        DYHomeActivityChildView *view=[[DYHomeActivityChildView alloc]init];
        view.imageNameStr=@"icon_headline";
        view.titleStr=@"商家头条";
        view.contentStr=@"发布商家活动头条";
        view;
    });
    
    self.line=({
        UILabel *line=[UILabel xhq_lineLabel];
        line;
    });
    [self addSubview:self.saleView];
    [self addSubview:self.newsView];
    [self addSubview:self.line];

    [self.saleView makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(0);
        make.width.equalTo(kScreenWidth/2);
    }];
    
    [self.newsView makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo(0);
        make.width.equalTo(kScreenWidth/2);
    }];
    
    [self.line makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(0);
        make.left.equalTo(kScreenWidth/2);
        make.width.equalTo(BILIWIDTH(0.7));
    }];
    
    @weakify(self);
    self.saleView.tapBlock = ^{
        @strongify(self);
        !self.activityBlock?:self.activityBlock(@"营销管理");
        
    };
    
    self.newsView.tapBlock = ^{
        @strongify(self);
         !self.activityBlock?:self.activityBlock(@"头条活动");
    };
}


@end

@interface DYHomeActivityChildView ()

@property (nonatomic,strong) UIImageView *iconImageView;
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *contentLabel;

@end

@implementation DYHomeActivityChildView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
-(void)initUI
{
    self.backgroundColor=WhiteColor;
    
    self.iconImageView = ({
        UIImageView *imageView=[Utils imageView];
        imageView;
    });
    
    self.titleLabel= ({
        UILabel *label=[Utils labelWithTitleFontSize:14 textColor:[UIColor xhq_aTitle] alignment:0];
        label;
    });
    
    self.contentLabel = ({
        UILabel *label=[Utils labelWithTitleFontSize:12 textColor:[UIColor xhq_content] alignment:0];
        label;
    });
    
    [self addSubview:self.iconImageView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.contentLabel];
    
    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(20));
        make.centerY.equalTo(self);
        make.width.height.equalTo(BILIHEIGHT(48));
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView.right).offset(BILIWIDTH(8));
        make.top.equalTo(BILIHEIGHT(15));
    }];
    
    [self.contentLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.bottom.equalTo(BILIHEIGHT(-15));
    }];
    
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
    [self addGestureRecognizer:tap];
}
-(void)tap
{
    if (self.tapBlock) {
        self.tapBlock();
    }
}
-(void)setImageNameStr:(NSString *)imageNameStr
{
    _imageNameStr=imageNameStr;
    self.iconImageView.image=[UIImage imageNamed:imageNameStr];
    
}

-(void)setTitleStr:(NSString *)titleStr
{
    _titleStr=titleStr;
    self.titleLabel.text=titleStr;
}

-(void)setContentStr:(NSString *)contentStr
{
    _contentStr=contentStr;
    self.contentLabel.text=contentStr;
}


@end



@interface DYHomeInviteView ()

@property (nonatomic,strong) UIImageView *bgView;
@property (nonatomic,strong) UIButton *goButton;

@end

@implementation DYHomeInviteView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
-(void)initUI
{
    self.backgroundColor=WhiteColor;
    
    self.bgView = ({
        UIImageView *view=[Utils imageViewWithImage:IMG(@"img_invited")];
//        view.contentMode=UIViewContentModeScaleToFill;
        view;
    });
    
    self.goButton = ({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(goButtonClick) target:self title:nil image:nil font:14 textColor:WhiteColor];
        button;
    });
    
    
    [self addSubview:self.bgView];
    [self addSubview:self.goButton];
    
    [self.bgView makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.equalTo(CGSizeMake(BILIWIDTH(355), BILIHEIGHT(78)));
    }];
    
    [self.goButton makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bgView).offset(BILIWIDTH(-10));
        make.centerY.equalTo(self.bgView).offset(BILIHEIGHT(3));
        make.width.height.equalTo(BILIHEIGHT(50));
    }];
    
}
-(void)goButtonClick
{
    !self.inviteBlock ? : self.inviteBlock();
}

@end
